
package com.honey.compilation.xml;

import java.util.ArrayList;
import java.util.List;

import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.IndentSpace;


public class TextElement extends AbstractElement {
	
	private List<String> contents;
	
	public TextElement() {
		contents = new ArrayList<String>();
	}
	public TextElement(String ...contents) {
		this();
		addContent(contents);
	}
	
	public void addContent(String ...contents){
		for(String content : contents){
			if(content != null){
				this.contents.add(content);
			}
		}	
	}
	
	public List<String> getContents() {
		return contents;
	}
	
	@Override
	public boolean isEmpyt() {
		
		return contents.size() == 0 ;
	}
	
	@Override
	public CharacterBuilder compiledContent(int indentLevel) {
		CharacterBuilder answer = CharacterBuilderFactory.createC16StringBuilder();
		String content = null;
		for(int i =0,size=contents.size();i<size;i++ ){
			content = contents.get(i);
			IndentSpace.spaceIndent(answer, indentLevel);
			answer.append(content);
			if( i+1<size){
				IndentSpace.newLine(answer);
			}
		}
		return answer;
	}
	
}
